package org.frogs.algo;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.StringTokenizer;

public class HistoryAnalizer {
	private static final String filename = System.getProperty("user.dir")
			+ "\\data\\history.txt";
	
	public static List<HistoryInfo> extractHistory () {
		List<HistoryInfo> result = new ArrayList<HistoryInfo>();
		
		File file = new File(filename);
		try {
            Scanner scanner = new Scanner(file);
 
            while (scanner.hasNextLine()) {
                StringTokenizer historyRow = new StringTokenizer (scanner.nextLine());
                String direction = historyRow.nextToken();
                Double distance = Double.parseDouble(historyRow.nextToken());
                result.add(new HistoryInfo(direction, distance));
            }
            scanner.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
		
		return result;
	}
	
	public static void main(String[] args) {
		List<HistoryInfo> infoList = extractHistory();
		for(HistoryInfo info : infoList) {
			System.out.println(info.getDirection() + " " + info.getDistance());
		}
	}
}
